﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ColorPickerControl;
using System.IO;
using System.IO.IsolatedStorage;


namespace Zeus.Classes
{
    public class ButtonProberties
    {
        public void GenerateCode(string Text)
        {
            StreamWriter writer = null;
            IsolatedStorageFile isolated = IsolatedStorageFile.GetUserStoreForApplication();
            IsolatedStorageFileStream strm = new IsolatedStorageFileStream("ezzat.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, isolated);
            writer = new StreamWriter(strm);
            writer.WriteLine(Text);
            writer.Close();
            strm.Close();
        }


        public void Content(Button B, TextBox TB)
        {
            if (TB.Text != "")
            {
                B.Content = TB.Text;
            }
            string text = B.Name + ".Content = " + TB.Text;
            GenerateCode(text);
        }
        //public void BGC(FrameworkElement C, ColorPicker CP)
        //{
        //    C.size
        //    C.Background = CP.SelectedColor;
        //}


        public void BackGroundColor(Button B, ColorPicker CP)
        {
            B.Background = CP.SelectedColor;
        }

        public void ForeColor(Button B, ColorPicker CP)
        {
            B.Foreground = CP.SelectedColor;
        }

        public void Enabled(Button B, CheckBox CB)
        {
            if (CB.IsChecked == false)
                B.IsEnabled = false;
            else
                B.IsEnabled = true;
        }

        public void Size(Button B, TextBox TB1, TextBox TB2)
        {           
            
            if (TB1.Text != "")
            {
                double x = double.Parse(TB1.Text);
                B.Width = x;
            }
            else
                B.Width = B.Width;
            if (TB2.Text != "")
            {
                double y = double.Parse(TB2.Text);
                B.Height = y;
            }
            else
                B.Height = B.Height;
        }

        public void Visible(Button B, ComboBox CB)
        {
            if (CB.SelectedItem.ToString() == "Visible")
                B.Visibility = Visibility.Visible;
            else
                B.Visibility = Visibility.Collapsed;

        }

        public void BorderThickness(Button B, TextBox TB1, TextBox TB2, TextBox TB3, TextBox TB4)
        {

            if (TB1.Text != "")
            {
                double w = double.Parse(TB1.Text);
                if (TB2.Text != "")
                {
                    double x = double.Parse(TB2.Text);
                    if (TB3.Text != "")
                    {
                        double y = double.Parse(TB3.Text);
                        if (TB4.Text != "")
                        {
                            double z = double.Parse(TB4.Text);
                            B.BorderThickness = new Thickness(w, x, y, z);
                        }
                    }
                }
            }
        }

        public void Opacity(Button B, TextBox TB)
        {
            if (TB.Text != "")
            {
                double x = double.Parse(TB.Text);
                if ((x >= 0) && (x <= 1))
                    B.Opacity = x;
            }
        }

        public void Margin(Button B, TextBox TB1, TextBox TB2, TextBox TB3, TextBox TB4)
        {


            if (TB1.Text != "")
            {
                double w = double.Parse(TB1.Text);
                if (TB2.Text != "")
                {
                    double x = double.Parse(TB2.Text);
                    if (TB3.Text != "")
                    {
                        double y = double.Parse(TB3.Text);
                        if (TB4.Text != "")
                        {
                            double z = double.Parse(TB4.Text);
                            B.Margin = new Thickness(w, x, y, z);
                        }
                    }
                }
            }
        }

        public void Name(Button B, TextBox TB)
        {
            if (TB.Text != "")
            {
                B.Name = TB.Text;
            }
        }

    }

}
